import { createRouter, RouteRecordRaw, createWebHashHistory } from "vue-router";
import Demo001 from "../components/Demo001.vue";
import Demo002 from "../components/Demo002.vue";
import { useTitle } from "@/utils";

const title = useTitle();

export const routes: RouteRecordRaw[] = [
  { path: "/", redirect: "/demo001", meta: { title: "" } },
  {
    path: "/demo001",
    component: Demo001,
    meta: { title: "1 入门" },
  },
  {
    path: "/demo002",
    component: Demo002,
    meta: { title: "2 中级" },
  },
];
const router = createRouter({
  history: createWebHashHistory(),
  routes,
});

router.beforeEach((to, _from) => {
  title.value = to.meta.title as string;
  return true;
});

export default router;
